package io.renren.modules.dataDisplay.controller;


import io.renren.common.utils.R;
import io.renren.modules.echarts.entity.AttendanceDate;
import io.renren.modules.echarts.entity.EchartsDate;
import io.renren.modules.echarts.entity.TeacherEvaltionPieEntity;
import io.renren.modules.echarts.service.AttendenceChartsService;
import io.renren.modules.echarts.service.TeacherEvaluationChartsService;
import io.renren.modules.echarts.service.TeacherPortraitService;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dataDisplay")
public class dataDisplayController {

    @Autowired
    TeacherEvaluationChartsService teacherEvaluationChartsService;
    @Autowired
    TeacherPortraitService teacherPortraitService;
    @Autowired
    AttendenceChartsService attendenceChartsService;

    @RequestMapping("getAllDisplayEcharts")
    public R getAllDisplayEcharts(@RequestParam Map<String, Object> params){
//        //用户名
//        String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
//        params.put("teacherId",username);
        //有课率查询
        List hasCourse =teacherEvaluationChartsService.getTeacherWorkEcharts(params);
//        //评教饼状图
//         List<TeacherEvaltionPieEntity> dataPie=teacherEvaluationChartsService.getTeacherEvaltionPie(params);
        //评教柱状图，分类别
//        List<EchartsDate> dataBar=teacherEvaluationChartsService.getTeacherEvaltionBar(params);
        //相符率
        List<TeacherEvaltionPieEntity>  CoincidenceRate=teacherEvaluationChartsService.getiMatchContentRate(params);
//        //分科目相符率
//        List<EchartsDate> rateBar=teacherEvaluationChartsService.getTeacherEvaltionRateBar(params);
        //授课时长纵向比
        Map<String,List> timeLine=teacherPortraitService.getTimeLineByCollege(params);
        //出勤情况
        List<AttendanceDate> teacherAttendancePie=teacherPortraitService.getTeacherAttendancePie(params);
        return R.ok().put("teacherAttendancePie", teacherAttendancePie).put("hasCourse",hasCourse).put("coincidenceRate",CoincidenceRate).put("timeLine",timeLine);
              //  .put("dataBar",dataBar).put("rateBar",rateBar).put("teacherAttendancePie",teacherAttendancePie)

    }

    @RequestMapping("getMycollegeDisplayEcharts")
    public R getMycollegeDisplayEcharts(@RequestParam Map<String, Object> params){
        //用户名
        SysUserEntity sysUserEntity = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal());
        String college=sysUserEntity.getCollege();
        //由于多参数需要,xml中使用了in(${})式请求，这里需要特殊对待 额外添加一对引号
        college=('\''+college+'\'');
        params.put("collegeName",college);
        //有课率查询
        List hasCourse =teacherEvaluationChartsService.getTeacherWorkEcharts(params);
//        //评教饼状图
//         List<TeacherEvaltionPieEntity> dataPie=teacherEvaluationChartsService.getTeacherEvaltionPie(params);
        //评教柱状图，分类别
//        List<EchartsDate> dataBar=teacherEvaluationChartsService.getTeacherEvaltionBar(params);
        //相符率
        List<TeacherEvaltionPieEntity>  CoincidenceRate=teacherEvaluationChartsService.getiMatchContentRate(params);
//        //分科目相符率
//        List<EchartsDate> rateBar=teacherEvaluationChartsService.getTeacherEvaltionRateBar(params);
        //授课时长纵向比
        Map<String,List> timeLine=teacherPortraitService.getTimeLineByCollege(params);
        //出勤情况
        List<AttendanceDate> teacherAttendancePie=teacherPortraitService.getTeacherAttendancePie(params);
        //授课平均时长排名
        Map<String,Object> averageTeacheingTime =teacherEvaluationChartsService.getAverageTeacheingTimeRanking(params);

        return R.ok().put("teacherAttendancePie", teacherAttendancePie).put("hasCourse",hasCourse).put("coincidenceRate",CoincidenceRate).put("timeLine",timeLine).put("averageTeacheingTime",averageTeacheingTime)
                //  .put("dataBar",dataBar).put("rateBar",rateBar).put("teacherAttendancePie",teacherAttendancePie)
                ;
    }

    @RequestMapping("/getTeacherDataEcharts")
    public R getTeacherDataEcharts(@RequestParam Map<String, Object> params) {
        //学院出勤情况横向比
        Map<String,Object> collegeTeacherEvaltion =teacherPortraitService.getTeacherAttendanceOfCollege(params);
        //学院授课时长横向比
        Map<String,List> collegeAverageTeacherTime =teacherPortraitService.getCollegeAverageTeacherTime(params);
        return R.ok().put("collegeTeacherEvaltion",collegeTeacherEvaltion).put("collegeAverageTeacherTime",collegeAverageTeacherTime);
    }

    @RequestMapping("/getAttendanceProfessionRanking")
    public R getAttendanceProfessionRankingFirstTen(@RequestParam Map<String, Object> params) {
        Map<String,List> horizontalComparison =attendenceChartsService.getAttendanceProfessionHorizontalComparison(params);
        Map<String,Object> rank =attendenceChartsService.getAttendanceProfessionRankingFirstTen(params);
        return R.ok().put("rank",rank).put("horizontalComparison",horizontalComparison);
    }

}
